<?php
namespace admin\action;

use herosphp\bean\Beans;
use herosphp\core\Controller;
use herosphp\http\HttpRequest;
use herosphp\session\Session;
use herosphp\utils\AjaxResult;

/**
 * @author yu
 */
class OfferAction extends CommonAction
{


    public function index(HttpRequest $request)
    {
        $page = $request->getParameter('page');
        $pagesize = $request->getParameter('pagesize');

        if ($page <= 0) $page = 1;
        if ($pagesize <= 0) $pagesize = 15;
        $this->page=$page;
        $this->pagesize=$pagesize;

        $search_arr=array(
          'start_time'=>$request->getParameter('starttime'),
          'end_time'=>$request->getParameter('endtime'),
          'saas_user_id'=>$this->loginUser->getSaasUserId(),

        );

        $service = Beans::get('offer.offer.service');
        $result = $service->getOfferList($pagesize,$page,$search_arr);

        $this->generatePageMenu($result['total']);

        $this->assign('items', $result['items']);
        $this->assign('breadcrumb', array('历史报价', '历史报价列表'));
        $this->setView("offer/offer_index");


    }

    public function add(HttpRequest $request)
    {
        $service = Beans::get('offer.offer.service');

        $this->setView("offer/offer_add");


    }

    public function details(HttpRequest $request)
    {
        $offer_id = $request->getParameter('offer_id');

        $service = Beans::get('offer.offer.service');

        $result['items'] = $service->getOfferProducts($offer_id);
        $result['head'] = $service->getOffer($offer_id);

        $this->assign('breadcrumb', array('历史报价', '历史报价列表','历史报价详情'));
        $this->assign('result', $result);
        $this->setView("offer/offer_detail");

    }

}
